using System;
using System.Collections.Generic;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

using FinancialAnalyzer.ToolClasses;
using FinancialAnalyzer.DataBase;

namespace FinancialAnalyzer.MoneyFlow
{
    [Serializable]
    public class MoneyFlowDB 
    {
        private Controller _incomeController;
        private Controller _outcomeController;
        private List<MoneyFlowItem> _itemList;
        private DateTime _currentDate;

        public MoneyFlowDB(String nameIncome, String nameOutcome)
        {
            _incomeController = new Controller(nameIncome, EFlowDirection.Income);
            _outcomeController = new Controller(nameOutcome, EFlowDirection.Outcome);
            _itemList = new List<MoneyFlowItem>();
            _currentDate = new DateTime(2008,12,12);
        }

        #region Properties
        public Controller IncomeController
        {
            get { return _incomeController; }
        }
        public Controller OutcomeController
        {
            get { return _outcomeController; }
        }
        public List<MoneyFlowItem> ItemList
        {
            get { return _itemList; }
        }
        public int CurrentMonth
        {
            get
            {
                return _currentDate.Month;
            }
        }
        public int CurrentYear
        {
            get
            {
                return _currentDate.Year;
            }
        }        
        #endregion
        
        #region public Methods
        public void refreshController()
        {
            _incomeController.Sum();
            _outcomeController.Sum();
        }
        public void refreshDate()
        {
            _currentDate = DateTime.Today;
        }
        public void initController(List<MoneyFlowItem> iList)
        {
            _itemList = iList;
            _incomeController.registerMoneyFlow(iList);
            _outcomeController.registerMoneyFlow(iList);
        }
        #endregion           

        #region Undo/Redo

        public void undo(EFlowDirection eFlowDirection)
        {
            switch (eFlowDirection)
            {
                case EFlowDirection.Income:
                    _incomeController.undo();
                    break;
                case EFlowDirection.Outcome:
                    _outcomeController.undo();
                    break;
                default:
                    break;
            }
        }

        public void redo(EFlowDirection eFlowDirection)
        {
            switch (eFlowDirection)
            {
                case EFlowDirection.Income:
                    _incomeController.redo();
                    break;
                case EFlowDirection.Outcome:
                    _outcomeController.redo();
                    break;
                default:
                    break;
            }
        }

        public void registerUndoState(EFlowDirection eFlowDirection, string[] path, Month month)
        {
            switch (eFlowDirection)
            {
                case EFlowDirection.Income:
                    /*_incomeController.registerUndoState(path, month)*/;
                    break;
                case EFlowDirection.Outcome:
                    /*_outcomeController.registerUndoState(path, month)*/;
                    break;
                default:
                    break;
            }
        }
        #endregion  
        
    }
}
